<?php

declare(strict_types=1);
/**
 * This file is part of Hyperf.
 *
 * @link     https://www.hyperf.io
 * @document https://hyperf.wiki
 * @contact  group@hyperf.io
 * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
 */
namespace App\Controller;

use App\Service\HealthLogService;
use Hyperf\Di\Annotation\Inject;

class HealthRecordController extends AbstractController
{
    /**
     * @Inject
     */
    protected HealthLogService $healthLogService;

    public function create()
    {
        $record['name'] = $this->request->input('name', '');
        $record['blood_pressure_high'] = $this->request->input('blood_pressure_high', 0);
        $record['blood_pressure_low'] = $this->request->input('blood_pressure_low', 0);
        $record['blood_sugar'] = $this->request->input('blood_sugar', 0);
        $record['heart_rate'] = $this->request->input('heart_rate', 0);
        $record['record_time'] = $this->request->input('record_time', '');
        $this->healthLogService->createLog($record);
        return $this->success();
    }

    public function recordList()
    {
        $res = $this->healthLogService->fetchRecords([]);
        return $this->success($res);
    }

    public function bloodSugarList()
    {
        $res = $this->healthLogService->fetchBloodSugar();
        return $this->success($res);
    }

    public function remove()
    {
        $id = (int) $this->request->input('id');
        $this->healthLogService->remove($id);
        return $this->success();
    }
}
